package com.osfw.dbadminer.enums;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public enum DbOperType {


    QUERY("query", "查询", "^(SELECT|WITH|CALL)"),
    ADD("add", "添加", "^(INSERT|CREATE)"),
    MODIFY("modify", "修改", "^(UPDATE|ALTER|MERGE)"),
    DELETE("delete", "删除", "^(DELETE|DROP|TRUNCATE)"),
    IMPORT("import", "导入", "^(IMPORT"),
    EXPORT("export", "导出", "^(EXPORT"),
    OTHER("other", "其他", "");

    private String type;
    private String name;
    private String pattern;

    DbOperType(String type, String name, String pattern) {
        this.type = type;
        this.name = name;
        this.pattern = pattern;
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public String getPattern() {
        return pattern;
    }

    public static DbOperType getDbOperType(String type) {
        for (DbOperType typeEnum : values()) {
            if (typeEnum.getType().equals(type)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static Map<String, String> getDbOperTypeList() {
        HashMap<String, String> map = new LinkedHashMap<>();
        for (DbOperType typeEnum : values()) {
            map.put(typeEnum.getType(), typeEnum.getPattern());
        }
        return map;
    }
}
